
<template>
  <div id="app" class="login-container">
    <div class="login-form">
      <h2 style="margin-bottom: 50px; color:gray">发送验证码重新设置密码</h2>
      <div class="form-group">
        <input v-model="form.photo" style="width: 200px" placeholder="请输入手机号" required />
      </div>
      <div class="form-group" style="height: 50px">
        <input v-model="form.yzm" style="width: 200px;float:left;" placeholder="请输入验证码" required />
        <p style="width: 80px; float:right;margin-top: 10px;color: #02aaf1" :style="spanStyle"  @click="sendCode()">发送验证码</p>
      </div>
      <h2 style="margin-bottom: 50px; color:gray">修改密码</h2>
      <div class="form-group">
        <input type="password" id="password" v-model="form.password1" placeholder="请输入新密码" required="required" />
      </div>
      <div class="form-group">
        <input type="password" id="password" v-model="form.password2" placeholder="请确认新密码" required="required" />
      </div>
      <el-button type="primary" @click="updatepassword()" class="dl">修改</el-button>
<!--      <el-button type="primary" @click="login()" class="dl">登录</el-button>-->
    </div>
  </div>
</template>

<style scoped>

.dl{
  margin-top: 5px;
}
span{
  color:gray;
  font-size: 14px;
}
input{
  border-radius: 4px;
}
#app {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #158eec; /* 蓝色背景 */
}

.login-form {
  background-color: white;
  padding: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  width: 300px;
  height: 450px;
  margin-left: 500px;
  border-radius: 4px
}


label {
  display: block;
  margin-bottom: 5px;
}

input {
  width: 100%;
  padding: 8px;
  box-sizing: border-box;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

.login-form {
  max-width: 300px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  text-align: center;
}

input {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 10px;
  box-sizing: border-box;
}

.captcha-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.captcha {
  cursor: pointer;
  font-size: 16px;
  color: blue;
  user-select: none;
}

button {
  display: block;
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}


</style>

<script>
export default {
  data() {
    return {
      form:{
        photo:"",
        yzm:""
      },

      spanStyle: {
        cursor: 'pointer' //鼠标经过小手标志
      },

      user:{},
      captchaCode: '',
    };
  },
  methods: {
    sendCode(){
      if (this.form.photo==null||this.form.photo==''){
        this.$message.error("请输入手机号")
        return;
      }
      if (!(/^1[3-9]\d{9}$/).test(this.form.photo)){
        this.$message.error("您输入的手机号格式不正确")
        return;
      }
      this.axios.post(`http://localhost:9009/user/sendCode?phone=${this.form.photo}`).then(res=>{
        var yzm=res.data.data;
        if (res.data.code==200){
          this.axios.post('http://localhost:9007/dx/send-sms', {
            signName: '智慧养老平台',
            templateCode: 'SMS_475105269',
            phoneNumbers: '17637908173',
            templateParam: JSON.stringify({ code: yzm })
          });
          this.$message.success("验证码发送成功,1分钟后失效请注意查看。验证码为："+res.data.data)
        }else {
          this.$message.error(res.data.msg)
        }
      })
    },
    updatepassword(){
      if (this.form.photo==null||this.form.yzm==null||this.form.photo==''){
        this.$message.error("手机号或验证码为空")
        return;
      }
      if (!(/^1[3-9]\d{9}$/).test(this.form.photo)){
        this.$message.error("您输入的手机号格式不正确")
        return;
      }

      if (this.form.password1==null || this.form.password1==''){
        this.$message.error('请填写新密码');
        return;
      }
      if (this.form.password2==null || this.form.password2==''){
        this.$message.error('请填写确认密码');
        return;
      }
      if (this.form.password1!=this.form.password2){
        this.$message.error('两次密码不一致');
      }
      this.axios.post(`http://localhost:9009/user/updatePassword2?phone=${this.form.photo}&password=${this.form.password1}`).then(res=>{
        if (res.data.code==200){
          this.$message.success("修改成功");
          location.href = '#/';
        }else{
          this.$message.error("修改失败");
        }
      })
    },

  },
  created() {

  }
};
</script>
